package com.wsj.spring.kafka.kafkademo.provider;

import com.google.gson.Gson;
import com.wsj.spring.kafka.kafkademo.bean.Message;
import com.wsj.spring.kafka.kafkademo.consts.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.UUID;

/**
 * 发送消息
 *
 * @author WangSongJun
 * @date 2018-06-30 21:24 星期六
 */
@Slf4j
@Component
public class KafkaSender {
    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;
    private Gson gson = new Gson();

    /**
     * 发送消息
     * 转String Json
     */
    public void send(String msg) {
        log.info("send msg:{}",msg);
        kafkaTemplate.send(Constants.TOPIC_1,msg);
    }

}
